﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using System.IO;
using WTwitter.Model.Twitter;
using WTwitter.Model.UserData;
using OAuthLib;
using WTwitter.Model.Utility;
using WTwitter.Model.Twitter.Json;
using System.Runtime.Serialization.Json;

namespace WTwitter.Model.Twitter.Utility {
	/// <summary>
	/// TwitterのStatus APIとやりとりするクラス
	/// </summary>
	static class StatusMethods {
		//APIのURL
		private static readonly string UpdateUrl = "http://twitter.com/statuses/update.json";

		/// <summary>
		/// Update
		/// </summary>
		/// <param name="text">投稿内容</param>
		/// <param name="info">認証情報</param>
		/// <returns>投稿した結果、サーバから返ってきたStatus</returns>
		public static Status Update(string text, AuthInfo info)  {
			var parameters = new RequestParameter[] {
				new RequestParameter() { Name = "status", Value= text}
			};
			return WebUtility<Status>.GetDeserializedJsonData(UpdateUrl, "POST", parameters, info);
		}

		/// <summary>
		/// Update
		/// </summary>
		/// <param name="text">投稿内容</param>
		/// <param name="replyToId">返信対象のStatusのID</param>
		/// <param name="info">認証情報</param>
		/// <returns>投稿した結果、サーバから返ってきたStatus</returns>
		public static Status Update(string text, long replyToId, AuthInfo info) {
			var parameters = new RequestParameter[] {
				new RequestParameter("status", text),
				new RequestParameter("in_reply_to_status_id", replyToId.ToString())
			};

			return WebUtility<Status>.GetDeserializedJsonData(UpdateUrl, "POST", parameters, info);
		}
	}
}
